From 8626fa725dbf72efbd936c7290a089f70a775a83 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 16 Aug 2014 22:38:32 -0700 Subject: [PATCH] Always generate a lockfile with dev-dependencies Previously an invocation of `cargo build` would generate a lockfile *without* dev dependencies, but an invocation of `cargo test` would generate a lockfile *with* dependencies. This causes odd problems and diffs with the lockfile. This commit switches the resolve-to-be-a-lockfile to using all dependencies of a package, while the resolve-to-be-compiled continues to use just the dependencies needed for the current build. --- src/cargo/ops/cargo_compile.rs | 2 +- tests/test_cargo_compile_git_deps.rs | 59 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 105ad0943..d7c44c19e 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -91,7 +91,7 @@ pub fn compile(manifest_path: &Path, } let resolved = try!(resolver::resolve(package.get_package_id(), - dependencies.as_slice(), + package.get_dependencies(), &mut registry)); try!(registry.add_overrides(override_ids)); diff --git a/tests/test_cargo_compile_git_deps.rs b/tests/test_cargo_compile_git_deps.rs index 4a857aea0..1523f2344 100644 --- a/tests/test_cargo_compile_git_deps.rs +++ b/tests/test_cargo_compile_git_deps.rs @@ -952,3 +952,62 @@ test!(dep_with_changed_submodule { .with_stderr("") .with_status(0)); }) + +test!(dev_deps_with_testing { + let p2 = git_repo("bar", |project| { + project.file("Cargo.toml", r#" + [package] + name = "bar" + version = "0.5.0" + authors = ["wycats@example.com"] + "#) + .file("src/lib.rs", r#" + pub fn gimme() -> &'static str { "zoidberg" } + "#) + }).assert(); + + let p = project("foo") + .file("Cargo.toml", format!(r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [dev-dependencies.bar] + version = "0.5.0" + git = '{}' + "#, p2.url()).as_slice()) + .file("src/main.rs", r#" + fn main() {} + + #[cfg(test)] + mod tests { + extern crate bar; + #[test] fn foo() { bar::gimme(); } + } + "#); + + // Generate a lockfile which did not use `bar` to compile, but had to update + // `bar` to generate the lockfile + assert_that(p.cargo_process("cargo-build"), + execs().with_stdout(format!("\ +{updating} git repository `{bar}` +{compiling} foo v0.5.0 ({url}) +", updating = UPDATING, compiling = COMPILING, url = p.url(), bar = p2.url()))); + + // Make sure we use the previous resolution of `bar` instead of updating it + // a second time. + assert_that(p.process(cargo_dir().join("cargo-test")), + execs().with_stdout(format!("\ +{compiling} bar v0.5.0 ({bar}#[..]) +{compiling} foo v0.5.0 ({url}) +{running} target[..]test[..]foo-[..] + +running 1 test +test tests::foo ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured + +", compiling = COMPILING, url = p.url(), running = RUNNING, bar = p2.url()))); +}) -- 2.30.2